import requests
from flask import Flask, jsonify, abort, request,Blueprint
file_name = "med_inv_1.jpg"
image_path = "pipeline/images/{}".format(file_name)
files = {"img":("med_inv_1.jpg",open(image_path,'rb'),{})}
from data_utils.standard_nlp import standout
import json
from predict import predictor
app=Flask(__name__)
@app.route("/nlp/predict/",methods =['get', 'post'], strict_slashes=False)
def main():
    file = request.json
    img_file=file["file_name"]
    # img_file= "med_inv_1.jpg"
    image_path = "pipeline/images/{}".format(img_file)
    files = {"img": (img_file, open(image_path, 'rb'), {})}
    # ocr final request form:
    #files = {"img":img_file,img_file,{}}
    res = requests.request("POST",url="http://120.92.92.149:8289/annotation",data={"type":"1"},files = files)
    orc_result = json.loads(res.text)
    confidence=orc_result["confidence"]
    result = predictor().nlp_predict(orc_result)
    result =standout(result,confidence)
    return jsonify(result)

if __name__=="__main__":
    app.run(host="0.0.0.0",port=10086,debug=True)

# if __name__=="__main__":
#     res = requests.request("POST",url="http://120.92.92.149:8289/annotation",data={"type":"1"},files = files)
#     orc_result = json.loads(res.text)
#     print(orc_result["confidence"])
#     # result = predictor().nlp_predict(orc_result)
#     # print(result)
